//
//  NetWorkingHandler.m
//  A段项目
//
//  Created by dllo on 16/1/24.
//  Copyright © 2016年 Scott. All rights reserved.
//

#import "NetWorkingHandler.h"

@implementation NetWorkingHandler

+ (void)netWorkingWithUrl:(NSString *)url complete:(void (^)(id))block {
    
    NSString *codeStr = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    
    NSURL *string = [NSURL URLWithString:codeStr];
    
    
    NSURLSession *session = [NSURLSession sharedSession];
    
    NSURLSessionDataTask *task = [session dataTaskWithURL:string completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
      
        dispatch_async(dispatch_get_main_queue(), ^{
            
            if (data) {
                
                id result = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
                
                block(result);
            }
            
        });
        
        
    }];
    
    [task resume];
    
}

@end
